// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: donggu

#include "coin2/exchange/base/feed_util/trade.h"

#include <gtest/gtest.h>

using coin2::exchange::feed::TradeSide;

TEST(TradeTest, Aggregation) {
  {
    Trade t {1, 2, 3, TradeSide::TRADE_SELL_NEGATIVE_SIDE, false};
    t.Clear();
    // printf("t = {%ld,%f,%f,%d}", t.timestamp, t.price, t.fill_qty, (int)(t.side));
    EXPECT_EQ(t, (Trade {0, 0, 0, TradeSide::TRADE_UNKNOWN_SIDE, false}));
  }

  {
    Trade t1 {};
    t1.Clear();
    Trade t2 {0, 1100, 220000, coin2::exchange::feed::TradeSide::TRADE_BUY_SIDE, false};
    EXPECT_FALSE(TryAggregateTrades(&t1, t2));
  }

  {
    Trade t1 {5, 1111, 330000, coin2::exchange::feed::TradeSide::TRADE_BUY_SIDE, false};
    Trade t2 {5, 1111, 420000, coin2::exchange::feed::TradeSide::TRADE_BUY_SIDE, false};
    EXPECT_TRUE(TryAggregateTrades(&t1, t2));
    EXPECT_EQ(
        t1,
        (Trade {5, 1111, 750000, coin2::exchange::feed::TradeSide::TRADE_BUY_SIDE, false}));
  }
}
